<template>
	<view id="login">	
		<Header txt="登录关联" v-if="baidu"></Header>
		<HeaderB txt="登录关联" v-if="!baidu"></HeaderB>
		<view class="top-tit">
			你好，
			<view class="tit">欢迎来到熊猫代理</view>
		</view>
		<view>		
			<input v-model="loginForm.account" placeholder="请输入手机号" autocomplete="off" />
		</view>
		<view>		
			<input type="password" password=true v-model="loginForm.password"  placeholder="请输入密码"  />
		</view>
		<label>
			<text class="pass" @click="gofo">忘记密码?</text>
		</label>
		<view  id="captcha1">	
		</view>
		<view class="">
			<button @click="changeLogin" class="loginbtn" >立刻登录</button>
			<button @click="gopage" class="registerbtn">去注册</button>
			<button @click="gopage2" class="registerbtn registerbtn2">返回密码登录</button>
		</view>	
	</view>
</template>

<script>
	import {formatDate2} from '../../common/com.js'
	export default {
		data() {
			return {
				loginForm: {
				        account: "",
				        password: "",
				        remember: true,
				      },
				dom: "",
				password: "",
				obj:{},
				isWx:false,
				baidu:true
			};
		},
		onShow() {
			// #ifdef MP-WEIXIN
				this.isWx=false
			// #endif
			// #ifdef MP-BAIDU
			this.baidu=false
			// #endif
		},
		computed:{
			go(){
				return this.$store.state.isLogin
			},
			firstLogin() {
			      return this.$store.state.firstLogin;
			    },
		},
		methods: {
			getCodeUrl(e){
				uni.login({
				  provider: 'weixin',
				  success: function (loginRes) {
					  console.log(123);
				  },
				})
				// let that = this;
				// this.$store
				//   .dispatch("GetCodeUrl")
				//   .then((response) => {
				// 		if(response.data.code==0){
				// 			console.log(response.data.obj);
				// 			that.getSetting(response.data.obj.code,response.data.obj.state) 
				// 		}
				//     // that.cert.status = response.data.obj.status;
				//   })
				//   .catch(() => {}); 

			// uni.showToast({
			// 	title: '授权失败，请确认授权已开启',
			// 	mask: true,
			// 	icon: 'none'
			// })
			},				
			//获取用户的当前设置
			getSetting(code,state) {
				let _params
				  _params = {
				    code: code,
				    state: state,
				    source: 'APP',
				  };  
				this.$store
				  .dispatch("CallBack",_params)
				  .then((response) => {
						if(response.data.code==0){
							
						}
				  })
				  .catch(() => {}); 
			},			
			gofo(){
				uni.navigateTo({
					url:"/pages/login/forgetPas"
				})
			},
			gopage(){
				uni.navigateTo({
					url:"/pagesA/user/weixinReg"
				})
			},
			gopage2(){
				uni.navigateTo({
					url:"/pages/login/login"
				})
			},
			getUserInfo() {
				let that = this;
				this.$store
				  .dispatch("GetInfo")
				  .then((response) => {
										
				    // that.cert.status = response.data.obj.status;
				  })
				  .catch(() => {});      
			},
			changeLogin() {
				let that=this
				let _params
				  _params = {
				    account: this.loginForm.account,
				    password: this.loginForm.password,
				    originType: 1,
				  };        
				this.$store
				  .dispatch("RelateAccount",
					_params
				  ).then((response)=>{
					  if(response.data.code==0){
						this.getUserInfo()
					  	uni.showModal({
					  		title: '登陆成功',
					  		content: '欢迎回来，尊敬的客户',
					  		success: function (res) {									
					  		    if (res.confirm) {
					  				let obj = {
					  				    account: that.loginForm.account,    
					  				    password:that.loginForm.password,       
					  				};
									that.$store.commit("login",obj)
									uni.setStorageSync('Cookie', response.header['Set-Cookie']);
									uni.login({
									success: (res) => {
									// 客户端代码
									console.log(res);
									uniCloud.callFunction({
									   	name: 'user-wx',
									   	data:{
											code:res.code
									   	},
									   	success(res){
									   		let data={
									   			id:res.result.openid
									   		}
									   		uni.setStorageSync('wxId',data)			 
									   	},
									   	fail(res){
									   		uni.showToast({
									   			title:"失败"+res
									   		})
									   	}
									})						
								}
							})
							uni.switchTab({
								url: "/pages/user/user"
							})		 
						} else if (res.cancel) {
					  		    console.log('用户点击取消');
					  		}
						}
					});
					}else{
						  uni.showModal({
							 title: response.data.msg
						  })
						  that.$store.commit("SET_VAL", false);
					  }
				  })
			},
		}
	}
</script>

<style lang="less" >
	#login{
		width: 90%;
		margin: 0 auto;
		.pass{
			margin-left: 30rpx;			
			font-size: 30rpx;
			color: #9A9A9A;
			cursor: pointer;
		}
		.loginbtn{
			margin: 0 auto;
			background-color: rgb(72, 110, 245);
			color: rgb(255, 255, 255);
			border-radius: 100rpx;
			margin-top: 80rpx;
		}
		.registerbtn{
			margin: 0 auto;
			background-color: rgb(255, 255, 255);
			color: rgb(153, 153, 153);
			border: 2rpx solid #cccccc;
			margin-top: 70rpx;
			width: 150rpx;
			font-size: 24rpx;
			border-radius: 100rpx;
		}
		.registerbtn{
			width: 250rpx;
		}
		.top-tit{
			font-size: 60rpx;
			color: #222222;
			font-weight: bold;
			margin-top: 80rpx;
			.tit{
				font-size: 36rpx;
				padding-top: 20rpx;
				margin-bottom: 100rpx;
			}   
		}
		input {
			width: 100%;
			height: 80rpx;
			margin-bottom: 10rpx;
			border-radius: 80rpx;
			background-color: #f4f4f4;
			color: #525252;
			padding-left: 20rpx;
			margin-bottom: 50rpx;
		}
		.span1 {
		      // float: left;
		      width: 14px;
			  height: 14px;
		      cursor: pointer;
		      color: #3373fc;
		      &:hover {
		        opacity: 0.8;
		      }
			  
		 }
		uni-checkbox .uni-checkbox-input {
			width: 14px;
			height: 14px;
		}
		button{
			margin-top: 30rpx;
			margin-bottom: 30rpx;
		}
		button::after{
			border:none;
		}
	}

</style>